package cn.com.hhrcw.base.data.mapstruct;

import cn.com.hhrcw.base.BaseConvert;
import cn.com.hhrcw.base.data.params.BlockDataParams;
import cn.com.hhrcw.base.data.vo.BlockDataVO;
import cn.com.hhrcw.base.data.vo.EnterpriseVO;
import cn.com.hhrcw.base.data.vo.PositionVO;
import cn.com.hhrcw.base.data.vo.SessionVO;
import cn.com.hhrcw.block.entity.BlockData;
import cn.com.hhrcw.entity.CmsContent;
import cn.com.hhrcw.entity.EnInfo;
import cn.com.hhrcw.entity.OpJob;
import cn.com.hhrcw.entity.SsSession;
import cn.com.hhrcw.es.entity.JobPositionDocument;
import cn.com.hhrcw.personal.cms.vo.CmsContentVO;
import cn.com.hhrcw.utils.ConvertUtil;
import cn.hutool.core.util.StrUtil;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.ReportingPolicy;

/**
 * @author lixingxing
 */
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE, imports = {ConvertUtil.class, StrUtil.class})
public interface BlockDataConvert extends BaseConvert<BlockData, BlockDataParams, BlockDataVO> {

    /**
     * toJobPosition
     * @param job
     * @param info
     * @return
     */
    @Mapping(target = "sourceId",source = "job.id")
    @Mapping(target = "name",source = "job.jobName")
    @Mapping(target = "logo",source = "info.enLogo")
    @Mapping(target = "companyName",source = "info.enName")
    @Mapping(target = "createTime",ignore = true)
    @Mapping(target = "salary",expression = "java(ConvertUtil.salary(job.getMinMoney(),job.getMaxMoney()))")
    @Mapping(target = "companyBenefits",expression = "java(StrUtil.split(info.getOtherWelfare(),','))")
    @Mapping(target = "workExperience",expression = "java(StrUtil.format(\"{}年-{}年\",job.getMinExperience(),job.getMaxExperience()))")
    PositionVO toJobPosition(OpJob job, EnInfo info);

    /**
     * toEnterprise
     * @param info
     * @return
     */
    @Mapping(target = "name",source = "info.enName")
    @Mapping(target = "createTime",ignore = true)
    EnterpriseVO toEnterprise(EnInfo info);

    /**
     * toSession
     * @param ssSession
     * @return
     */
    @Mapping(target = "sourceId",source = "id")
    @Mapping(target = "image",source = "imageFileId")
    SessionVO toSession(SsSession ssSession);

    /**
     * toCmsContent
     * @param cmsContent
     * @return
     */
    CmsContentVO toCmsContent(CmsContent cmsContent);

}

